package com.ossfk.jt808.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.ossfk.jt808.client.Jt808Client;
import com.ossfk.net.config.NetClientConfig;

@Configuration
public class Jt808ClientConfig {
	@Value("${ossfk.jt808.client.host:127.0.0.1}")
	private String host;
	@Value("${ossfk.jt808.client.port:8000}")
	private Integer port;
	@Value("${ossfk.jt808.client.keepAlive:true}")
	private Boolean keepAlive;
	@Value("${ossfk.jt808.client.readerIdleTimeSeconds:60}")
	private Long readerIdleTimeSeconds;
	@Value("${ossfk.jt808.client.name:Jt808Client}")
	private String name;
	@Value("${ossfk.jt808.client.autoConnect:false}")
	private Boolean autoConnect;
	@Value("${ossfk.jt808.client.phoneNum:}")
	private String phoneNum;
	@Value("${ossfk.jt808.client.devid:}")
	private String devid;
	@Value("${ossfk.jt808.client.autoConnectSeconds:10}")
	private Long autoConnectSeconds;

	@Bean
	public NetClientConfig netClientConfig() {
		NetClientConfig config = new NetClientConfig(host, port);
		config.setKeepAlive(keepAlive);
		config.setReaderIdleTimeSeconds(readerIdleTimeSeconds);
		config.setName(name);
		config.setAutoConnect(autoConnect);
		config.setAutoConnectSeconds(autoConnectSeconds);
		config.setPhoneNum(phoneNum);
		config.setDevid(devid);
		return config;
	}

	@Bean
	public Jt808Client jt808Server(NetClientConfig netClientConfig) {
		Jt808Client client = new Jt808Client(netClientConfig);
		return client;
	}
}
